package com.kintreda.ieco_server.module.home.web;

import com.kintreda.ieco_server.bean.account.User;
import com.kintreda.ieco_server.core.web.BaseController;
import com.kintreda.ieco_server.core.web.R;
import com.kintreda.ieco_server.module.order.service.IRecycleRecordService;
import com.kintreda.ieco_server.module.order.service.IWasteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Created by IntelliJ IDEA
 * @Project_Name ieco_server
 * @Package com.kintreda.ieco_server.module.home
 * @Author ZhongYao_H
 * @Date 2019/5/15:20:00
 * @Year 2019 Month 05 Day 15
 * @Date_zh 2019 年 五月 星期三
 */
@Controller
public class HomeController extends BaseController {

    @Autowired
    IWasteService wasteService;
    @Autowired
    IRecycleRecordService recycleRecordService;

    @RequestMapping("/home")
    public ModelAndView indexBack(){
        return new ModelAndView("background-image");
    }


    @RequestMapping("/echarts")
    @ResponseBody
    public Object echrats(){
        R r = R.ok();
        User loginUser = getUser();
        if (loginUser!=null){
            if (loginUser.getType().equals("3")){
                //机构管理员则查看机构的数据
                r.put("wasteData",wasteService.wasteDataByOrgId(loginUser.getOrgId()));
                r.put("epvalue",recycleRecordService.ePValue(loginUser.getOrgId()));
                r.put("wasteMax",new String[]{});
                return r;
            }
        }

        r.put("wasteData",wasteService.wasteDataAll());
        r.put("wasteMax",wasteService.wasteDataMax());
        r.put("epvalue",recycleRecordService.ePValueAll());
        return r;
    }
}
